# -*- coding:utf-8 -*-

from libs.handler import BaseHandler
from libs.utils  import get_taobao_id

class Index(BaseHandler):
	def get(self):
		
		hots = self.db.query("SELECT id,pic_url,price,title FROM items ORDER BY id DESC LIMIT 8");
		clothes = self.db.query("SELECT id,pic_url,price,title FROM items WHERE group_id=1 ORDER BY id DESC LIMIT 7");
		shoes = self.db.query("SELECT id,pic_url,price,title FROM items WHERE group_id=2 ORDER BY id DESC LIMIT 7");
		bags = self.db.query("SELECT id,pic_url,price,title FROM items WHERE group_id=3 ORDER BY id DESC LIMIT 7");
		self.render('index.html', hots = hots, clothes =clothes, shoes=shoes, bags = bags)
		

class GetItemInfo(BaseHandler):
	def get(self):
		
		from libs.taobao import Taobao
		
		url = self.get_argument("url",None)
		id  = get_taobao_id(url)
		if id is not None:
			ret = Taobao('item.get').fetch(num_iid = id)
			end()
class About(BaseHandler):
	def get(self, type="index"):
		self.render("about/"+type+".html");
			
		
	
handlers = []
handlers = [
	(r"/",Index),
	(r"/about/",About),
	(r"/about/(\w+)",About),
	(r"/ajax/get_item_info",GetItemInfo)
	]

